package game.util;

public class StringUtils {

	public static String replace(String board, int idx, char c) {
		char str[] = board.toCharArray();
		str[idx] = c;
		return new String(str);
	}

	public static String swap(String board, int i, int j) {
		char str[] = board.toCharArray();
		char tmp = str[i];
		str[i] = str[j];
		str[j] = tmp;
		return new String(str);
	}

	public static int charCount(String board, char c) {
		int cnt = 0;
		for (int i = 0; i < board.length(); ++i) {
			if (board.charAt(i) == c) {
				cnt++;
			}
		}
		return cnt;
	}

	public static String swapAll(String board, char a, char b) {
		char str[] = board.toCharArray();
		for (int i = 0; i < str.length; ++i) {
			if (str[i] == a) {
				str[i] = b;
			} else if (str[i] == b) {
				str[i] = a;
			}
		}
		return new String(str);
	}

}
